# def test(label):
#     label.setText("I love you everyday.")

import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
from matplotlib.patches import Circle, Rectangle

def test(label):
    # 创建图形对象和子图
    fig, ax = plt.subplots()
    ax.set_xlim(-60, 60)
    ax.set_ylim(-60, 60)
    ax.set_aspect('equal')

    # 创建初始图形对象
    circle = Circle((0, 0), radius=0, fc='blue', alpha=0.5)
    rectangle = Rectangle((-50, -50), width=0, height=0, fc='red', alpha=0.5)
    ax.add_patch(circle)
    ax.add_patch(rectangle)

    # 创建标签
    label_obj = ax.annotate("", xy=(0, 0), fontsize=12, ha='center')
    label_obj.set_position((0.5, 0.95))  # 设置标签位置
    label_obj.set_text("I love you everyday.")

    # 设置标签与窗口大小一致
    ax.set_position([0, 0, 1, 1])

    # 更新函数
    def update(frame):
        t = frame / frames  # 计算当前时间占总时长的比例
        if t <= 0.5:
            # 绘制蓝色圆形
            circle.set_radius(50 * t)
            circle.set_facecolor('blue')
            label_obj.set_text("I love you everyday. (Circle)")
        else:
            # 绘制红色方块
            rectangle.set_width(100 * (t - 0.5))
            rectangle.set_height(100 * (t - 0.5))
            rectangle.set_xy((-50 * (t - 0.5), -50 * (t - 0.5)))
            rectangle.set_facecolor('red')
            label_obj.set_text("I love you everyday. (Rectangle)")

        return circle, rectangle, label_obj

    # 设置帧数和总时长
    frames = 100
    ani_duration = 3  # 动画时长为3秒

    # 创建动画
    ani = FuncAnimation(fig, update, frames=frames, interval=(ani_duration * 1000) / frames, blit=True)

    plt.show()

